#pragma once
#include <QFile>
#include <QFileInfo>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QMap>
#include <QProgressBar>
#include <QPushButton>
#include <QString>
#include <QVBoxLayout>
#include <QWidget>
#include <QVBoxLayout>
#include <QTime>


class TransferBox : public QGroupBox
{
    Q_OBJECT

public:
    enum Direction { SendDirection, ReceiveDirection, DoneDirection };
    Direction direction;

    TransferBox(int id, QString filename, quint64 filesize, QWidget *parent = 0);
    TransferBox(int id, QString filepath, QWidget *parent = 0);
    ~TransferBox();

    //TransferBox(int id, QWidget *parent = 0);

    void receive(QByteArray bytes);
    QByteArray send();
public slots:
    void finishedTransfer();
    void cancelTransfer();


signals:
    void finishedSending(int id);
    void remove(int id); //must be removed by connection
    void cancel(int id);

private slots:
    void openFile();
    void updateProgress();
    void removeTransfer();


private:
    void construct(int id, QString filename, TransferBox::Direction dir);
    QString getSavePath(QString filename);

    QPushButton *cancelButton;
    QFile *file;
    QFileInfo *fileInfo;

    bool isTransferring;
    int id;

    quint64 transferred;
    quint64 fileSize;
    //used for formatting
    quint64 sizeDivisor;
    QString postfix;

    QTime transferTimer;


    QProgressBar *progressBar;
    QLabel *statusLabel, *fileLabel;
    QHBoxLayout *buttonLay;
};
